package com.tinyseed.emcp.api.basicdata.service.impl;

import com.tinyseed.emcp.api.app.common.DateUtil;
import com.tinyseed.emcp.api.app.config.DataSourceKey;
import com.tinyseed.emcp.api.app.config.TargetDataSource;
import com.tinyseed.emcp.api.basicdata.domain.MonitorRstData;
import com.tinyseed.emcp.api.basicdata.repository.history.MonitorRstDataDataSource2Repository;
import com.tinyseed.emcp.api.basicdata.service.MonitorRstDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;

import javax.transaction.Transactional;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.Optional;

@Service
public class MonitorRstDataServiceImpl implements MonitorRstDataService {

    @Autowired
    private MonitorRstDataDataSource2Repository monitorRstDataDataSource2Repository;

    @Override
    @TargetDataSource(DataSourceKey.SHARDING)
    public void get() {
        LocalDateTime localDateTime = LocalDateTime.of(2020,6,20,0,0);
         monitorRstDataDataSource2Repository.save(
                MonitorRstData.builder().dataTime(Timestamp.valueOf(localDateTime)).build()
        );
    }
    @Override
    public void get2() {

        Optional<MonitorRstData> m = monitorRstDataDataSource2Repository.findById(65530757L);
        System.out.println(m.toString());
    }
}
